package com.itsq.controller.resources;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.base.BaseController;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.bean.Response;
import com.itsq.pojo.dto.PageCompanyDto;
import com.itsq.pojo.dto.PageDepartmentDto;
import com.itsq.pojo.entity.Company;
import com.itsq.pojo.entity.Department;
import com.itsq.service.resources.DepartmentService;
import com.itsq.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 史先帅
 * @since 2021-01-30
 */
@RestController
@RequestMapping("/department")
@AllArgsConstructor
@CrossOrigin
@Api(tags = "科室信息模块")
public class DepartmentController  extends BaseController {

    @Autowired
    private DepartmentService departmentService;

    @PostMapping("selCompanyPageFront")
    @ApiOperation(value = "科室信息模块前台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Department>> selDepartmentPageFront(@RequestBody PageDepartmentDto pageDepartmentDto){
        Page<Department> DepartmentPage = departmentService.selDepartmentPageFront(pageDepartmentDto);
        return Response.success(DepartmentPage);
    }

    @PostMapping("selCompanyPageAfter")
    @ApiOperation(value = "管理员——科室信息模块后台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Department>> selDepartmentPageAfter(@RequestBody PageDepartmentDto pageDepartmentDto){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        Page<Department> DepartmentPage = departmentService.selDepartmentPageAfter(pageDepartmentDto);
        return Response.success(DepartmentPage);
    }

    @PostMapping("insert")
    @ApiOperation(value = "管理员——科室信息模块添加", notes = "", httpMethod = "POST")
    public Response<Integer> insert(@RequestBody Department department){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(departmentService.insert(department));
    }

    @PostMapping("update")
    @ApiOperation(value = "管理员——科室信息模块修改", notes = "", httpMethod = "POST")
    public Response<Integer> update(@RequestBody Department department){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(departmentService.update(department));
    }


    @PostMapping("selDepartmentList")
    @ApiOperation(value = "科室信息模块list查询", notes = "", httpMethod = "POST")
    public Response<List<Department>> selDepartmentList(){
        return Response.success(departmentService.selDepartmentList());
    }

    @PostMapping("selDepartmentId")
    @ApiOperation(value = "科室信息模块id查询", notes = "", httpMethod = "POST")
    public Response<Department> selDepartmentId(Integer id){
        return Response.success(departmentService.selDepartmentId(id));
    }

    @PostMapping("selDepartment")
    @ApiOperation(value = "科室信息模块根据单位id查询", notes = "", httpMethod = "POST")
    public Response<List<Department>> selDepartment(Integer companyId){
        return Response.success(departmentService.selDepartment(companyId));
    }

    @PostMapping("delete")
    @ApiOperation(value = "科室信息模块删除", notes = "", httpMethod = "POST")
    public Response<Integer> delete(Integer id){
        return Response.success(departmentService.delete(id));
    }
}

